<?php
namespace app\admin\controller;
use app\BaseController;
use think\facade\Db;
use think\facade\Request;
//use think\facade\Route;
use think\facade\View;
class Order
{
    public function orderList()
    {
        $keywords= Request::post('keywords');
        $begin= Request::post('begin');
        $end= Request::post('end');
        $xq= Request::post('xq');
        $dq= Request::post('dq');
        $cid= Request::post('cid');
        $post = Request::post();
        $where = [];
        if (isset($keywords) && $keywords <> '')                    $where[] = ['order_sn','like',"%{$keywords}%"];
        //if (isset($post['begin']) && $post['begin'] <> '' &&  isset($post['end']) && $post['end'] <> '') $where[] = ['addtime','BETWEEN TIME',"{$post['begin']},{$post['end']}"];
        if (isset($post['xq']) && $post['xq'] <> '' &&  isset($post['dq']) && $post['dq'] <> '') $where[] = ['price','BETWEEN',"{$post['xq']},{$post['dq']}"];
        if (isset($post['begin']) && !empty($post['begin'])) $where[] = ['addtime','> TIME',$post['begin']];
        if (isset($post['end']) && !empty($post['end'])) $where[] = ['addtime','< TIME',$post['end']];

        if (isset($post['cid'])) $where[] = ['o.status','in',$post['cid']];
        $list = Db::table('ecm_order')->alias('o')
            ->join(" ecm_order_status s","o.status=s.status_id")
            ->field('id,aname,order_status,addtime,price,remark,order_sn')
            ->where($where)
            ->select();

        $lista = Db::table('ecm_order_status')->alias('o')
            ->select();

        View::assign('keywords',$keywords);
        View::assign('begin',$begin);
        View::assign('end',$end);
        View::assign('xq',$xq);
        View::assign('dq',$dq);
        View::assign('cid',$cid);
        View::assign($post);
        View::assign('list',$list);
        View::assign('lista',$lista);
        return View::fetch();
    }

    public function orderDetail()
    {
        return view();
    }
}